package com.chb.controller;

import com.chb.annotation.LogAnnotation;
import com.chb.model.entity.Branch;
import com.chb.model.vo.PageBean;
import com.chb.model.vo.Result;
import com.chb.service.BranchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: 陈海彬
 * @date: Created in 2023/9/26 17:50
 * @description:
 * @modified By:
 * @version:
 */
@RestController
@RequestMapping("/branch")
public class BranchController {
    @Autowired
    private BranchService branchService;



    @GetMapping("/list")
    public Result getAllInfo() {
        Result allBranch = branchService.findAllBranch();
        return allBranch;
    }

    @GetMapping("/info")
    public Result info() {
        Result result = branchService.selectAll();
        return result;
    }

    /**
     * @param
     * @return com.chb.model.vo.Result
     * @create by: 陈海彬
     * @description: 获取平调分店下拉框信息
     * @create time: 2023/10/3 13:48
     */
    @GetMapping("/flatInformation")
    public Result flatInformation() {
        return branchService.flatInformation();
    }

    /**
     * @param
     * @return
     * @create by: xIAO_ZHOU
     * @description: 店铺信息页面===> 展示所有店铺信息（店长、开店时间...）以及该店员工人数
     * @create time: 2023/9/30 22:14
     */

    @PostMapping("/store")
    public PageBean<Branch> selestBranchInfo(Integer currentPage, Integer pageSize, String branchname) {
        PageBean<Branch> result = branchService.selectAllBranchAndStaff(currentPage, pageSize, branchname);
        return result;
    }

    /**
     * @param
     * @return
     * @create by: xIAO_ZHOU
     * @description: 根据店铺名称模糊查询店铺信息
     * @create time: 2023/10/5 19:54
     */
    @PostMapping("/query")
    @LogAnnotation(business_type = "查询店铺信息")
    public Result queryselestBranchInfoByBranchname(@RequestBody Branch branchname) {
        Result result = branchService.queryBranchInfoBybranchname(branchname);
        return result;
    }

    /**
     * @param
     * @return
     * @create by: xIAO_ZHOU
     * @description:添加新的店铺及信息
     * @create time: 2023/10/5 19:55
     */
    @PostMapping("/insert")
    @LogAnnotation(business_type="添加新的店铺")
    public Integer insertNewBranch(@RequestBody Branch branch) {
        Integer integer = branchService.insertNewBranch(branch);
        return integer;

    }

    /**
     * @param branch
     * @return java.lang.Integer
     * @create by: xIAO_ZHOU
     * @description: 通过店铺id 进行修改店铺信息
     * @create time: 2023/10/5 20:38
     */
    @PostMapping("/update")
    @LogAnnotation(business_type="修改店铺信息")
    public Integer UpdateBranch(@RequestBody Branch branch) {
        Integer integer = branchService.updateBranch(branch);
        return integer;
    }

    /**
     * @param
     * @return
     * @create by: xIAO_ZHOU
     * @description: 通过店铺id 进行修改店铺状态（营业/整顿）
     * @create time: 2023/10/8 11:32
     */
    @PostMapping("/adjust")
    public Integer adjustBranch(@RequestBody Branch branch) {
        Integer integer = branchService.adjustBranch(branch);
        return integer;
    }

    /**
     * @param
     * @return
     * @create by: xIAO_ZHOU
     * @description: 通过店铺id 删除店铺信息
     * @create time: 2023/10/8 15:12
     */
    @PostMapping("/delete")
    @LogAnnotation(business_type="删除店铺")
    public Integer delBranch(@RequestBody Branch branch) {
        Integer integer = branchService.delBranch(branch);
        return integer;

    }
    /**
     * @create by: xIAO_ZHOU
     * @description: 查询所删除的店铺是否存在商品
     * @create time: 2023/10/13 10:58
     * @param
     * @return
     */
    @PostMapping("/queryProduct")
    public Result queryProduct(@RequestBody Branch branch) {
        Result result = branchService.queryProduct(branch);
        return result;
    }


    /**
     * @param
     * @return
     * @create by: xIAO_ZHOU
     * @description: 查询在职且没有安排岗位的员工（可以安排为店长的员工）
     * @create time: 2023/10/8 15:57
     */
    @PostMapping("/noArrangementBranch")
    public Result selectNoArrangementBranch() {
        Result result = branchService.selectNoArrangementBranch();
        return result;

    }

    /**
     * @param
     * @return
     * @create by: xIAO_ZHOU
     * @description: 确定员工为新店的店长后，将该员工之前的branchid 修改为新店的branchid
     * @create time: 2023/10/9 11:17
     */
    @PostMapping("/changBranch")
    public Integer changeBranchid(@RequestBody Branch branch) {
        Integer integer = branchService.changeBranchid(branch);
        return integer;
    }

    /**
     * @param
     * @return
     * @create by: xIAO_ZHOU
     * @description: 给店铺添加上店长的staffid
     * @create time: 2023/10/9 15:44
     */
    @PostMapping("/updateManager")
    public Integer updateStaffidforBranch(@RequestBody Branch branch) {
        Integer integer = branchService.updateStaffidforBranch(branch);
        return integer;
    }

    /**
     * @param
     * @return
     * @create by: xIAO_ZHOU
     * @description: 确定员工为新店的店长后，将该员工之前的roleid 修改为店长的roleid
     * @create time: 2023/10/9 19:23
     */
    @PostMapping("/changeRoleid")
    public Integer changeRoleid(@RequestBody Branch branch) {
        Integer integer = branchService.changeRoleid(branch);
        return integer;

    }

    /**
     * @param
     * @return
     * @create by: xIAO_ZHOU
     * @description: 根据员工的staffid 查询roleid 再查询rolename
     * @create time: 2023/10/9 19:48
     */
    @PostMapping("/RoleNameByStaffid")
    public Result selectRoleNameByStaffid(@RequestBody Branch branch) {
        Result result = branchService.selectRoleNameByStaffid(branch);
        return result;

    }

    /**
     * @param
     * @return
     * @create by: xIAO_ZHOU
     * @description: 加载店长调离框中所有职位信息
     * @create time: 2023/10/9 20:38
     */
    @PostMapping("/selectAllRoleName")
    public Result selectAllRoleName() {
        Result result = branchService.selectAllRoleName();
        return result;

    }


    /**
     * @param
     * @return
     * @create by: xIAO_ZHOU
     * @description: 加载店长调离框中所有店名
     * @create time: 2023/10/9 20:38
     */
    @PostMapping("/selectAllBranchName")
    public Result selectAllBranchName() {
        Result result = branchService.selectAllBranchName();
        return result;
    }

    /**
     * @param
     * @return
     * @create by: xIAO_ZHOU
     * @description: 调离后将原来店铺的店长staffid改为 null
     * @create time: 2023/10/10 11:25
     */
    @PostMapping("/changeManagerStaffid")
    public Integer changeManagerStaffid(@RequestBody Branch branch) {
        Integer integer = branchService.changeManagerStaffid(branch);
        return integer;
    }

    /**
     * @param
     * @return
     * @create by: xIAO_ZHOU
     * @description: 调离后将原来店铺的店长branchid改为 新店的branchid
     * @create time: 2023/10/10 11:46
     */
    @PostMapping("/changeManagerBranchid")
    public Integer changeManagerBranchid(@RequestBody Branch branch) {
        Integer integer = branchService.changeManagerBranchid(branch);
        return integer;
    }

    /**
     * @param
     * @return
     * @create by: xIAO_ZHOU
     * @description: 调离后将原来店铺的店长deptid改为 新店的deptid
     * @create time: 2023/10/10 11:46
     */
    @PostMapping("/changeManagerRoleid")
    public Integer changeManagerRoleid(@RequestBody Branch branch) {
        Integer integer = branchService.changeManagerRoleid(branch);
        return integer;
    }

}